package com.obrempon.credit.market.httptest.api;

import androidx.annotation.NonNull;

import com.obrempon.credit.market.configs.ObremponApiUrl;
import com.obrempon.credit.market.utils.shared.ObremponSharedHelper;
import com.obrempon.credit.market.utils.shared.ObremponSharedKey;
import com.obrempon.module.easyhttp.config.IRequestApi;
import com.obrempon.module.easyhttp.config.IRequestBodyStrategy;
import com.obrempon.module.easyhttp.config.IRequestInterceptor;
import com.obrempon.module.easyhttp.config.IRequestType;
import com.obrempon.module.easyhttp.model.HttpHeaders;
import com.obrempon.module.easyhttp.model.HttpParams;
import com.obrempon.module.easyhttp.model.RequestBodyType;
import com.obrempon.module.easyhttp.request.HttpRequest;

import java.io.File;

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/EasyHttp
 *    time   : 2019/12/14
 *    desc   : 上传图片
 */
public final class UpdateImageApi implements IRequestApi, IRequestType, IRequestInterceptor {

    @NonNull
    @Override
    public String getApi() {
        String url = ObremponApiUrl.OBREMPON_UPLOAD_FILE_URL;
        //地区转发
        String timeZone = ObremponSharedHelper.INSTANCE.queryObremponSharedString(ObremponSharedKey.OBREMPON_TIMEZONE);
        if (!timeZone.isEmpty()){
            return "/"+timeZone + url;
        }
        return ObremponApiUrl.INSTANCE.queryEasyHttpUrl(true,-1);
    }

    /** 本地图片 */
    private File image;

    public UpdateImageApi(File image) {
        this.image = image;
    }

    public UpdateImageApi setImage(File image) {
        this.image = image;
        return this;
    }

    @NonNull
    @Override
    public IRequestBodyStrategy getBodyType() {
        return RequestBodyType.FORM;
    }

    @Override
    public void interceptArguments(@NonNull HttpRequest<?> httpRequest, @NonNull HttpParams params, @NonNull HttpHeaders headers) {
        params.setMultipart(true);
        IRequestInterceptor.super.interceptArguments(httpRequest, params, headers);
    }

    public static final class ImageBean {
        private int code;
        private String msg;
        private Image obj;

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        public Image getObj() {
            return obj;
        }

        public void setObj(Image obj) {
            this.obj = obj;
        }

        public static final class Image{
            private String url;

            public String getUrl() {
                return url;
            }

            public void setUrl(String url) {
                this.url = url;
            }
        }
    }

}